package com.yc.eduservice.controller;

import com.hz.apiservice.model.request.ApiResponse;
import com.yc.eduservice.model.entities.CourseEntity;
import com.yc.eduservice.service.CourseService;
import com.yc.eduservice.service.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/edu")
public class StudentController {
    @Resource
    StudentService studentService;
    @Resource
    CourseService courseService;

    @PostMapping("/manager/edit-course")
    public String editCourse(@RequestParam("id") int id, @RequestParam("courseName") String courseName,
                             @RequestParam("courseCode") String courseCode, @RequestParam("teacherId") int teacherId,
                             @RequestParam("sectionCount") int sectionCount, @RequestParam("courseTime") String courseTime,
                             @RequestParam("maxStudentCount") int maxStudentCount, @RequestParam("courseProfile") String courseProfile,
                             @RequestParam("textbook") String textbook, @RequestParam("creditsCount") int creditsCount,
                             @RequestParam("allScore") int allScore, @RequestParam("passScore") int passScore) {
        studentService.editCourse(id, courseName, courseCode, teacherId, sectionCount, courseTime, maxStudentCount, courseProfile, textbook, creditsCount, allScore, passScore);
        return "success";
    }

    @PostMapping("/manager/delete-course")
    public String deleteCourse(int id) {
        studentService.deleteCourse(id);
        return "success";
    }

    @PostMapping("/manager/view-course")
    public CourseEntity viewCourse(int id) {
        return studentService.viewCourse(id);

    }

    @PostMapping("/manager/view-selected-students")
    public Map viewSelectedStudents(int id) {
        return studentService.viewSelectedStudents(id);
    }



    @PostMapping("/student/apply-re-exam")
    public String applyReExam(@RequestParam("courseId")int courseId,@RequestParam("studentId") int studentId) {
        return studentService.applyReExam(courseId, studentId);
    }

    @PostMapping("/student/my-score")
    public Map myScore(int studentId) {
        return studentService.myScore(studentId);
    }
//学生选课
    @PostMapping("/student/select-course")
    public String selectCourse(@RequestParam("courseId")int courseId,@RequestParam("studentId") int studentId){
        int select=studentService.selectCourse(courseId,studentId);
        return select>0? ApiResponse.ok(select):ApiResponse.intError();
    }
    @PostMapping("/student/cancel-course")
    public String cancelCourse(@RequestParam("courseId")int courseId,@RequestParam("studentId") int studentId){
        return ApiResponse.ok(studentService.cancelCourse(courseId,studentId));
    }
    @GetMapping("/all-courses")
    public String allCourses(){
        return ApiResponse.ok(courseService.allCourse());
    }
    @GetMapping("/student/selected")
    public String selected(@RequestParam("studentId")Integer studentId){
        return ApiResponse.ok(studentService.selectedCourses(studentId));
    }
    @GetMapping("/student/selected-info")
    public String selectedInfo(@RequestParam("courseId")int courseId,@RequestParam("studentId") int studentId){
       return ApiResponse.ok(studentService.selectedCourseInfo(studentId,courseId));
    }
}
